package com.lcc.lynx.security.config;

import com.lcc.lynx.common.converter.StringToDateConverter;
import com.lcc.lynx.excel.interceptor.ExcelInterceptor;
import com.lcc.lynx.security.interceptor.LoginInterceptor;
import com.lcc.lynx.security.interceptor.PermissionInterceptor;
import com.lcc.lynx.security.interceptor.RepeatSubmitInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
class WebConfigurer implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Autowired
    private ExcelInterceptor excelInterceptor;

    @Autowired
    private PermissionInterceptor permissionInterceptor;

    @Autowired
    private RepeatSubmitInterceptor repeatSubmitInterceptor;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**");
        registry.addInterceptor(repeatSubmitInterceptor).addPathPatterns("/**");
        registry.addInterceptor(permissionInterceptor).addPathPatterns("/**");
        registry.addInterceptor(excelInterceptor).addPathPatterns("/**");
    }

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(new StringToDateConverter());
    }

}